var answerRecord = new Object();
var questionType = {
    "01":"单选题",
    "02":"多选题",
    "03":"判断题",
    "05":"简答题"
};
var userList = [];
var userInfo = {};
answerRecord.init = function () {
    answerRecord.getAnswerUsers();
    answerRecord.initQuestion();
};

// 加载题目答题记录
answerRecord.initQuestion = function () {
    var params = {
        'projectId':$("#projectId").val(),
        'templateId': $("#templateId").val(),
        'userId':$("#userId").val()
    };
    $.ajax({
        url: appPath + "/admin/projectEstimate/questionAnswerRecord",
        data: params,
        async: false,
        type: "post",
        dataType: "json",
        success: function (data) {
            var result = data.result;
            var html = '', item, options, option;
            var questionTitleFiles = [],questionFile, optionFiles = [];
            for (var i = 0; i < result.length; i++) {
                item = result[i];
                html += '<div class="questionDiv">';
                html += '<h3>题目' + (i+1) + '：'+item.varQuestionsContent+'（'+questionType[item.chrType]+'）</h3>';
                // 题目图片
                questionTitleFiles = item.questionTitleFiles;
                for(var j=0;j<questionTitleFiles.length;j++){
                    questionFile = questionTitleFiles[j];
                    html += '<img src="' +questionFile.mimeUrl + '" width="100px" height="100px;"/>';
                }
                // 简答题
                if('05' == item.chrType){
                    if(item.hasOwnProperty('answerContent'))
                    html += '<p>'+item.answerContent+'</p>';
                //选择题
                }else{
                    if(item.hasOwnProperty('options')){
                        options = item.options;
                        for(var j=0;j<options.length;j++){
                            option = options[j];
                            html += '<p';
                            if(option.hasOwnProperty('answer')){
                                html += ' style="color:red;"'
                            }
                            html += '>'+option.oType+'.'+option.optionContent+'</p>';
                            if(option.hasOwnProperty('mimeUrl')){
                                html += '<img src="' +option.mimeUrl + '" width="100px" height="100px;"/>';
                            }
                        }
                    }
                }

                html += '</div>';
            }
            $("#div").html(html);
        }
    });
};


// 答题人员list
answerRecord.getAnswerUsers = function () {
    var params = {
        'projectId':$("#projectId").val(),
        'templateId': $("#templateId").val(),
        'userId':$("#userId").val()
    };
    $.ajax({
        url: appPath + "/admin/projectEstimate/getAnswerUsers",
        data: params,
        async: false,
        type: "post",
        dataType: "json",
        success: function (data) {
            var result = data.result;
            userList = result;
            $("#total").html(result.length);
            userInfo = result[0];
            $("#userDept").html(userInfo.department_name);
            $("#userCompany").html(userInfo.company_name);
            $("#userName").html(userInfo.user_name);
            $("#userId").val(userInfo.id);
        }
    });
};

// 上一个 下一个
answerRecord.changeOne = function (type) {
    var now = $("#now").html();
    var showIndex = 0;
    if('before' == type){
        if(1== now){
            layer.msg("当前已是第一位!")
            return;
        }
        $("#now").html(Number(now)-1);
        showIndex = Number(now) -2;
    }else{
        if(userList.length == now){
            layer.msg("当前已是最后一位!")
            return;
        }
        $("#now").html(Number(now)+1);
        showIndex = Number(now);
    }
    userInfo = userList[showIndex];
    $("#userDept").html(userInfo.department_name);
    $("#userCompany").html(userInfo.company_name);
    $("#userName").html(userInfo.user_name);
    $("#userId").val(userInfo.id);
    answerRecord.initQuestion();
}



